package pub.gll.plugin.asm.model;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author hujianqiang
 */
public final class AspectClassManager {
    private HashSet<String> aspectClassNameList = new HashSet<>();
    private AtomicBoolean atomicIsIncrement = new AtomicBoolean(false);

    private AspectClassManager() {
    }

    private static class AspectClassManagerHolder {
        private static AspectClassManager INSTANCE = new AspectClassManager();
    }

    public static AspectClassManager getInstance() {
        return AspectClassManagerHolder.INSTANCE;
    }


    public void addAspect(String aspectClassName) {
        aspectClassNameList.add(aspectClassName);
    }
    public void addAllAspect(Collection<String> allAspectClassName) {
        aspectClassNameList.addAll(allAspectClassName);
    }

    public void clear(){
        aspectClassNameList.clear();
    }

    public HashSet<String> aspect() {
        return aspectClassNameList;
    }

    public boolean contains(Set<String> files) {
        if (files.isEmpty() || aspectClassNameList.isEmpty()) return false;
        return files.stream().anyMatch(s -> aspectClassNameList.stream().anyMatch(aspectClassName -> {
                    if (s.contains(aspectClassName)) {
                        return true;
                    }
                    return false;
                })
        );

    }

    public void setIsIncrement(boolean isIncrement) {
        atomicIsIncrement.set(isIncrement);
    }

    public boolean isIncrement() {
        return atomicIsIncrement.get();
    }
}
